import 'package:flutter/material.dart';

class GoodsItem extends StatefulWidget {
  GoodsItem({super.key, required this.item});
  Map<String, dynamic> item;

  @override
  State<GoodsItem> createState() => _GoodsItemState();
}

class _GoodsItemState extends State<GoodsItem> {
  Map<String, dynamic> item = {
    "created": "2022.05.04",
    "enablePickUp": true,
    "endAddress": "广州广州广州广州广州广州广州",
    "planArrivalTime": "2025.05.03",
    "startAddress": "顺德顺德顺德顺德顺德顺德顺德顺德顺德顺德顺德顺德顺德顺德顺德顺德",
    "status": "1",
    "transportTaskId": "xxx123456"
  };

// 根据状态status获取运输数据
  getStatus(String status) {
    switch (status) {
      case '1':
        return '待提货';
      case '2':
        return '在途';
      case '3':
        return '改派';
      case '4':
        return '已交付';
      case '5':
        return '已作废';
      default:
        return '未知';
    }
  }

  // 初始化
  @override
  void initState() {
    super.initState();
    setState(() {
      item = widget.item;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(bottom: 10),
      color: Colors.white,
      padding: const EdgeInsets.all(10),
      child: Column(children: [
        // 第一行
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              '任务编号： ${item['transportTaskId']}',
              style: const TextStyle(fontSize: 16, color: Colors.black),
            ),
            Container(
              padding: const EdgeInsets.all(3),
              decoration: BoxDecoration(
                border: Border.all(color: Colors.red, width: 1),
                borderRadius: const BorderRadius.all(Radius.circular(10)),
              ),
              child: Text(getStatus('${item['status']}'),
                  style: const TextStyle(fontSize: 12, color: Colors.red)),
            )
          ],
        ),
        const SizedBox(height: 15),
        // 第二行
        Row(
          children: [
            Container(
                width: 25,
                height: 25,
                decoration: const BoxDecoration(
                  color: Colors.black,
                  borderRadius: BorderRadius.all(Radius.circular(15)),
                ),
                child: const Center(
                  child: Text(
                    '起',
                    style: TextStyle(color: Colors.white, fontSize: 12),
                  ),
                )),
            const SizedBox(width: 10),
            // 起始地址
            Expanded(
                child: Text(
              '${item['startAddress']}',
              style: const TextStyle(color: Colors.grey),
            ))
          ],
        ),
        const SizedBox(height: 10),
        // 第三行
        Row(
          children: [
            Container(
                width: 25,
                height: 25,
                decoration: const BoxDecoration(
                  color: Colors.red,
                  borderRadius: BorderRadius.all(Radius.circular(15)),
                ),
                child: const Center(
                  child: Text(
                    '止',
                    style: TextStyle(color: Colors.white, fontSize: 12),
                  ),
                )),
            const SizedBox(width: 10),
            // 起始地址
            Expanded(
                child: Text(
              '${item['endAddress']}',
              style: const TextStyle(color: Colors.grey),
            ))
          ],
        ),

        // 分割线
        const Divider(height: 20, color: Color.fromARGB(255, 228, 225, 225)),

        // 第四行
        Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
          Column(children: [
            const Text('提货时间：', style: TextStyle(color: Colors.grey)),
            Text('${item['created']}'),
          ]),
          // 提货按钮 - 背景色为红色
          ElevatedButton(
              style: ButtonStyle(
                  backgroundColor: WidgetStateProperty.all(Colors.red)),
              onPressed: () {},
              child: const Text('提货', style: TextStyle(color: Colors.white))),
        ])
      ]),
    );
  }
}
